package a51qindian.com.comprehensive.activity;

import android.content.Intent;
import android.view.WindowManager;

import java.util.Timer;
import java.util.TimerTask;

import a51qindian.com.comprehensive.Const;
import a51qindian.com.comprehensive.R;
import a51qindian.com.comprehensive.base.QDBaseActivity;
import a51qindian.com.comprehensive.util.SpUtil;


/**
 * Author: Li
 * Date: 2017/9/20 0020
 * Description: 欢迎界面
 */

public class WelcomeActivity extends QDBaseActivity {

    @Override
    protected void initSth() {
        super.initSth();
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        countDown(2000);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_welcome;
    }

    private void countDown(int delay) {
        Timer timer = new Timer();
        TimerTask timerTask = new TimerTask() {
            @Override
            public void run() {
                if (SpUtil.isUserExist(WelcomeActivity.this)) {
                    //当用户等级为商铺 并且未完善信息时前往完善信息界面
                    if (SpUtil.getUserInfo(WelcomeActivity.this, SpUtil.USER_GRADE).equals(Const.TYPE_SHOP)
                            && SpUtil.getUserInfo(WelcomeActivity.this, SpUtil.USER_IS_SHOP).equals("0")) {
                        startActivity(new Intent(WelcomeActivity.this, PerfectShopInfoActivity.class));
                    } else {
                        Intent intent = new Intent(WelcomeActivity.this, MainActivity.class);
                        intent.putExtra(Const.USER_TYPE,
                                SpUtil.getUserInfo(WelcomeActivity.this, SpUtil.USER_GRADE));
                        startActivity(intent);
                    }
                } else {
                    startActivity(new Intent(WelcomeActivity.this, LoginActivity.class));
                }

                WelcomeActivity.this.finish();
            }
        };
        timer.schedule(timerTask, delay);
    }
}